/**
 * 悬浮菜单
 */
(function($) {
	$.fn.hoverMenu = function() {
		$(this).addClass('hover-menu');
		
		var menu = $(this).find("ul").get(0);
		var link = $(this).find("a").get(0);
		
		var maxw = 0;
		$(menu).find("li").each(function(){
			var width = parseInt(jQuery(this).css('width')) || '180';
			maxw = Math.max( width, maxw );
		});
		$(menu).css('width',maxw+'px');
		$(link).hoverIntent({
			over: function(e){
				$(menu).css('display','inline').css('top',$(this).height()+'px');
				// Make sure if doesn't go off screen
				var offset = parseInt(jQuery(menu).position().left);
				var width = parseInt(jQuery(menu).css('width'));
				var wind = parseInt(jQuery(window).width());
				if( parseInt(offset+width) > wind ) {
					jQuery(menu).css('right', '10px');
				}
			},
			out: function(){ 
			},
			timeout: 220,
			sensitivity: 8,
			interval: 100
		});
		$(document).mouseover(function(e){$(menu).css('display','none');});
		$(this).mouseover(function(e){e.stopPropagation();});
		return this;
	};
})(jQuery);
